/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class BabyMonitorDAO {
	public static BabyMonitor loadBabyMonitorByORMID(int codSystem) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadBabyMonitorByORMID(session, codSystem);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor getBabyMonitorByORMID(int codSystem) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getBabyMonitorByORMID(session, codSystem);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByORMID(int codSystem, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadBabyMonitorByORMID(session, codSystem, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor getBabyMonitorByORMID(int codSystem, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return getBabyMonitorByORMID(session, codSystem, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByORMID(PersistentSession session, int codSystem) throws PersistentException {
		try {
			return (BabyMonitor) session.load(orm.BabyMonitor.class, new Integer(codSystem));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor getBabyMonitorByORMID(PersistentSession session, int codSystem) throws PersistentException {
		try {
			return (BabyMonitor) session.get(orm.BabyMonitor.class, new Integer(codSystem));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByORMID(PersistentSession session, int codSystem, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (BabyMonitor) session.load(orm.BabyMonitor.class, new Integer(codSystem), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor getBabyMonitorByORMID(PersistentSession session, int codSystem, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (BabyMonitor) session.get(orm.BabyMonitor.class, new Integer(codSystem), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor[] listBabyMonitorByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listBabyMonitorByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor[] listBabyMonitorByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return listBabyMonitorByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor[] listBabyMonitorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.BabyMonitor as BabyMonitor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (BabyMonitor[]) list.toArray(new BabyMonitor[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor[] listBabyMonitorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.BabyMonitor as BabyMonitor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (BabyMonitor[]) list.toArray(new BabyMonitor[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadBabyMonitorByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return loadBabyMonitorByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		BabyMonitor[] babyMonitors = listBabyMonitorByQuery(session, condition, orderBy);
		if (babyMonitors != null && babyMonitors.length > 0)
			return babyMonitors[0];
		else
			return null;
	}
	
	public static BabyMonitor loadBabyMonitorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		BabyMonitor[] babyMonitors = listBabyMonitorByQuery(session, condition, orderBy, lockMode);
		if (babyMonitors != null && babyMonitors.length > 0)
			return babyMonitors[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateBabyMonitorByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iterateBabyMonitorByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateBabyMonitorByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Taller1PDSPersistentManager.instance().getSession();
			return iterateBabyMonitorByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateBabyMonitorByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.BabyMonitor as BabyMonitor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateBabyMonitorByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.BabyMonitor as BabyMonitor");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor createBabyMonitor() {
		return new orm.BabyMonitor();
	}
	
	public static boolean save(orm.BabyMonitor babyMonitor) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().saveObject(babyMonitor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.BabyMonitor babyMonitor) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().deleteObject(babyMonitor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.BabyMonitor babyMonitor)throws PersistentException {
		try {
			if(babyMonitor.getUserCodUser() != null) {
				babyMonitor.getUserCodUser().setBabyMonitor(null);
			}
			
			if(babyMonitor.getDoctoridDoctor() != null) {
				babyMonitor.getDoctoridDoctor().setBabyMonitor(null);
			}
			
			if(babyMonitor.getDiagnose() != null) {
				babyMonitor.getDiagnose().setBabyMonitorCodSystem(null);
			}
			
			if(babyMonitor.getQuestForm() != null) {
				babyMonitor.getQuestForm().setBabyMonitorCodSystem(null);
			}
			
			return delete(babyMonitor);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.BabyMonitor babyMonitor, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(babyMonitor.getUserCodUser() != null) {
				babyMonitor.getUserCodUser().setBabyMonitor(null);
			}
			
			if(babyMonitor.getDoctoridDoctor() != null) {
				babyMonitor.getDoctoridDoctor().setBabyMonitor(null);
			}
			
			if(babyMonitor.getDiagnose() != null) {
				babyMonitor.getDiagnose().setBabyMonitorCodSystem(null);
			}
			
			if(babyMonitor.getQuestForm() != null) {
				babyMonitor.getQuestForm().setBabyMonitorCodSystem(null);
			}
			
			try {
				session.delete(babyMonitor);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.BabyMonitor babyMonitor) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().refresh(babyMonitor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.BabyMonitor babyMonitor) throws PersistentException {
		try {
			orm.Taller1PDSPersistentManager.instance().getSession().evict(babyMonitor);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static BabyMonitor loadBabyMonitorByCriteria(BabyMonitorCriteria babyMonitorCriteria) {
		BabyMonitor[] babyMonitors = listBabyMonitorByCriteria(babyMonitorCriteria);
		if(babyMonitors == null || babyMonitors.length == 0) {
			return null;
		}
		return babyMonitors[0];
	}
	
	public static BabyMonitor[] listBabyMonitorByCriteria(BabyMonitorCriteria babyMonitorCriteria) {
		return babyMonitorCriteria.listBabyMonitor();
	}
}
